package org.ljy.testdemo.controller;


import lombok.extern.slf4j.Slf4j;
import org.ljy.testdemo.common.Result;
import org.ljy.testdemo.model.UserInfo;
import org.ljy.testdemo.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {


    @Qualifier(value = "u1")
    @Autowired
    public UserInfo userInfo;




    @RequestMapping("/login")
    public Result login(String userName, String password){
        //前面一堆验证工作，这里根据自己的业务功能写
        //………………
        UserInfo userInfo = new UserInfo();
        //账目密码验证完成，就可以给用户发放令牌了
        Map<String,Object> cliams = new HashMap<>();
        cliams.put("id", userInfo.getId());
        cliams.put("name", userInfo.getUserName());
        //获取对应的token
        String jwt = JwtUtils.genJwt(cliams);
        //返回token
        return Result.success(jwt);
    }
}
